package com.dameng.jianyouquan.mvp.view.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;

import com.dameng.jianyouquan.R;
import com.dameng.jianyouquan.base.mvpBase.BaseMvpActivity;
import com.dameng.jianyouquan.base.mvpBase.BasePresenter;
import com.dameng.jianyouquan.mvp.model.ForgetPwdModel;
import com.dameng.jianyouquan.mvp.presenter.impl.ModifyPwdPresenterImpl;
import com.dameng.jianyouquan.mvp.view.view.ForgetPwdView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ForgetPwdActivity extends BaseMvpActivity implements ForgetPwdView {

    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.et_modifyPwd_phone)
    EditText etModifyPwdPhone;
    @BindView(R.id.et_modifyPwd_verification_code)
    EditText etModifyPwdVerificationCode;
    @BindView(R.id.btn_modifyPwd_send_verification_code)
    Button btnModifyPwdSendVerificationCode;
    @BindView(R.id.et_modify_pwd)
    EditText etModifyPwd;
    @BindView(R.id.et_modify_pwd_confirm)
    EditText etModifyPwdConfirm;
    @BindView(R.id.btn_modifyPwd_reset)
    Button btnModifyPwdReset;
    private ModifyPwdPresenterImpl modifyPwdPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_forget_pwd);
        ButterKnife.bind(this);
    }

    @Override
    protected void initData() {

    }

    @Override
    protected BasePresenter createPresenter() {
        modifyPwdPresenter = new ModifyPwdPresenterImpl(new ForgetPwdModel(), this);
        return modifyPwdPresenter;
    }

    @Override
    public void sendVerificationCodeSuccess() {
        showToast("已发送验证码");
    }

    @Override
    public void sendVerificationCodeFail(String msg) {
        showToast(msg);
    }

    @Override
    public void modifyPwdSuccess() {
        showToast("密码重置成功");
        finish();
        startActivity(new Intent(ForgetPwdActivity.this, LoginActivity.class));
    }

    @Override
    public void modeifyPwdFail(String msg) {
        showToast(msg);
    }

    @OnClick({R.id.iv_back, R.id.btn_modifyPwd_send_verification_code, R.id.btn_modifyPwd_reset})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.btn_modifyPwd_send_verification_code:
                modifyPwdPresenter.sendVerificationCode(etModifyPwdPhone.getText().toString().trim());
                break;
            case R.id.btn_modifyPwd_reset:
                modifyPwdPresenter.modifyPwd(etModifyPwdPhone.getText().toString().trim(),etModifyPwdVerificationCode.getText().toString().trim(),etModifyPwd.getText().toString().trim(),etModifyPwdConfirm.getText().toString().trim());
                break;
        }
    }
}
